package it.unibz.ti2.internetPizzeria.entities;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;


/**
 * Storing information about orders
 *
 */
@Entity
@Table(name = "ORDERS")
public class Order {

	@Id
	@GeneratedValue
	@Column(name = "ORDER_ID")
	private long id;

	@ManyToOne
	@JoinColumn(name = "ORDER_CUSTOMER_FK")
	private Customer customer;

	@OneToMany(mappedBy = "order")
	private List<OrderProduct> orderProducts;

	@Column(name = "ORDER_DATETIME")
	private Date orderedDate;

	@Column(name = "ORDER_STATUS")
	private String status;

	@OneToOne
	@JoinColumn(name = "ORDER_DELIVERY")
	private Delivery delivery;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public Delivery getDelivery() {
		return delivery;
	}

	public void setDelivery(Delivery delivery) {
		this.delivery = delivery;
	}

	public List<OrderProduct> getOrderProducts() {
		return orderProducts;
	}

	public void setOrderProducts(List<OrderProduct> orderProducts) {
		this.orderProducts = orderProducts;
	}

	public Date getOrderedDate() {
		return orderedDate;
	}

	public void setOrderedDate(Date orderedDate) {
		this.orderedDate = orderedDate;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public float getOrderPrice() {
		float result = (float) 0.0;
		for (OrderProduct orderProduct : this.orderProducts) {
			result += orderProduct.getQuantity()
					* orderProduct.getProduct().getPrice();
		}
		return result;
	}

	public static final String StatusAwaitingPreparation = "Awaiting preparation";
	public static final String StatusInPreparation = "In preparation";
	public static final String StatusReadyToDeliver = "Ready to deliver";
	public static final String StatusInDelivery = "In delivery";
	public static final String StatusDelivered = "Delivered";
	public static final String StatusNotDelivered = "Not delivered";
	public static final String StatusCancelled = "Cancelled";

}
